<template>
  <div class="register">
    <div class="register_form">
      <h3>欢迎注册</h3>
      <el-form
        status-icon
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="用户名" prop="username">
          <el-input
            type="text"
            v-model="ruleForm.userName"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input
            type="password"
            v-model="ruleForm.passWord"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="昵称" prop="nicname">
          <el-input
            type="text"
            v-model="ruleForm.nicname"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-select
          v-model="ruleForm.value"
          placeholder="请选择"
          @change="changeUser"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <el-form-item>
          <el-button type="primary" @click="submitForm">登录</el-button>
          <el-button @click="resetForm">提交注册</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        userName: "",
        passWord: "",
        nicname: "",
        value: "",
      },
      options: [
        {
          value: "管理员",
          label: "管理员",
        },
        {
          value: "员工",
          label: "员工",
        },
      ],
    };
  },
  methods: {
    submitForm() {
      this.$router.push("/login");
    },
    resetForm() {
      this.$http
        .post("/api/register", {
          userName: this.ruleForm.userName,
          passWord: this.ruleForm.passWord,
          auth: this.ruleForm.value,
          nicname: this.ruleForm.nicname,
        })
        .then((res) => {
          if (res.data.code === 1) {
            this.ruleForm = {
              userName: "",
              passWord: "",
              nicname: "",
              value: "",
            };
            this.$router.push("/login");
          }
        });
    },
    changeUser() {},
  },
};
</script>

<style scoped lang='scss'>
.register {
  width: 100%;
  height: 100%;
  background-color: rgb(0, 4, 27);
  .register_form {
    width: 800px;
    height: 500px;
    margin: 0 auto;
    background: white;
  }
}
.el-select {
  margin-left: 90px;
  margin-bottom: 20px;
}
</style>